﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;

namespace Tester.DL645.Core
{
    /// <summary>
    /// 
    /// </summary>
    public static class AddressField
    {

        /// <summary>
        /// 
        /// </summary>
        /// <param name="address"></param>
        /// <returns></returns>
        public static string Reverse(byte[] address)
        {
            return string.Concat(address.Reverse().Select(b => b.ToString("X2")));
        }

       
        /// <summary>
        /// 反转地址
        /// </summary>
        /// <param name="address"></param>
        /// <returns></returns>
        public static List<byte> Reverse(string address,int len,char pad)
        {
            return Reverse(address.PadLeft(len, pad));

        }
        /// <summary>
        ///  反转地址
        /// </summary>
        /// <param name="address"></param>
        /// <returns></returns>
        public static List< byte> Reverse(string address)
        {

            List<string> list = new List<string>();

            for (int i = 0; i < address.Length; i = i + 2)
            {
                list.Add(address.Substring(i,2));
            }
            list.Reverse();

            return list.Select(item => (byte)int.Parse(item, System.Globalization.NumberStyles.HexNumber))
                  .ToList();
                 
        }
    }
}
